using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace Edenbrook.BizTalk.BuildGenerator.CommandBuilders
{
    /// <summary>
    /// Builds the command for calling the unit tests
    /// </summary>
    public class UnitTestsCommandBuilder : ICommandBuilder 
    {
        private const string UnitTestsCommand = "\t\t<Exec Command='\"$(VS80COMNTOOLS)..\\IDE\\mstest.exe\" {0} /runconfig:{1}' />";
        private const string TestContainerTag = " /testcontainer:{0} ";
        private const string CommandTag = "<!-- @UnitTestCommand@ -->";

        #region ICommandBuilder Members
        /// <summary>
        /// Implements the build method
        /// </summary>
        /// <param name="args"></param>
        /// <param name="fileBuilder"></param>
        public void Build(GenerationArgs args, StringBuilder fileBuilder)
        {
            StringBuilder containerBuilder = new StringBuilder();

            foreach(UnitTestContainer container in args.UnitTesting.TestContainers)
            {
                containerBuilder.Append(string.Format(CultureInfo.InvariantCulture, TestContainerTag, PathHelper.MakeConfigurable(container.Location)));             
            }
            string command = string.Format(CultureInfo.InvariantCulture, UnitTestsCommand, containerBuilder.ToString(), args.UnitTesting.TestRunConfigPath);      
            fileBuilder.Replace(CommandTag, commandBuilder.ToString());
        }

        #endregion
    }
}
